﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SMS.Entities.BaseClasses;
using SMS.Common.Silverlight;
using System.ComponentModel;
using System.Collections.Generic;
using SMS.Entities;
using SMS.Entities.Master;
using System.Windows.Data;


namespace SMS.ViewModel.Master
{
    public class MainMasterViewModel:BaseNotify 
    {
        SMS.Model.MainMasterModel _model;
        public MainMasterViewModel()
        {
            SelectCommand = new DelegateCommand(Search, null);
            _model = new Model.MainMasterModel();
            _model.OnSelectCompleted += new Action<System.Collections.ObjectModel.ObservableCollection<Entities.Menu.Menu>>(_model_OnSelectCompleted);
            _model.OnServiceError += new Action<SMSException>(_model_OnServiceError);
            _model.SelectMenu("Master");
        }

        void _model_OnServiceError(SMSException obj)
        {
            ErrorMessage = obj.Message;
            UserMessage = string.Empty;
            //throw new NotImplementedException();
        }

        void _model_OnSelectCompleted(System.Collections.ObjectModel.ObservableCollection<Entities.Menu.Menu> obj)
        {
            if (obj != null)
            {
                MenuList = new List<Entities.Menu.Menu>(obj);
            }
          //  throw new NotImplementedException();
        }
        private List<Entities.Menu.Menu> _menuList;

        public List<Entities.Menu.Menu> MenuList
        {
            get { return _menuList; }
            set { _menuList = value; OnPropertyChanged("MenuList"); }
        }
        public ICommand SelectCommand { get; private set; }
        private void Search(object param)
        {
            //_model.SelectMenu("Master");
        }
    }
}
